<?php
//属性控制器
class Controller_Admin_Attr extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'attr';
        parent::__construct($req, $res);

        $this->_list_where = array(
        );

        $this->_shopId = App_Shop_Manager::currentShopId();
        if ($this->_shopId > 0)
            $this->_list_where[] = array('shopId', '=', $this->_shopId);
    }

	//默认首页
    public function action_index ()
    {
        $this->action_list();
    }

	//添加属性
    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }

        parent::action_create();
    }

    public function action_delete ($nid)
    {
        App_Attr::remove($nid);
        $this->to_url('list');
    }

	//修改属性信息
    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        else
        {
            $data = Form_Data::detail($this->_form_type, $nid); 
            $this->_form_data = $data;
        }

        parent::action_update($nid);
    }

	//属性详细信息
    public function action_detail ($nid)
    {
        $data = Form_Data::detail($this->_form_type, $nid); 
        $this->_form_data = $data;

        parent::action_detail($nid);
    }

	//数据格式重构
    private function rebuild_post_data (& $post)
    {
        //
        $post['uid'] = user::current_user_id();
        if ($post['type'] == 'MAINCAT')
            $post['parentId'] = 0;
    }

	//显示属性信息
    public function list_get_data ($offset, $limit)
    {
        return App_Attr::all_attrs($offset, $limit, FALSE, $this->_list_where);
    }


    public function classname_by_list_row (& $row)
    {
        if ($row['type'] == '属性值')
            return 'subcat';
        else
            return 'maincat';
    }

    public function actions_by_list_row (& $row, & $menus)
    {
        if ($row['type'] == '属性值')
        {
        }
    }
}
